<template>
  <div>
    <el-table
        :data="tableData"
        style="width: 100%"
        :default-sort="{prop: 'date', order: 'descending'}"
    >
      <el-table-column prop="id" label="编号" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column prop="realName" sortable label="申述人" header-align="center" align="center"
                       width="180"></el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="申述时间"></el-table-column>
      <el-table-column prop="connect" header-align="center" align="center" label="申述内容"></el-table-column>
      <el-table-column label="操作" header-align="center" align="center">
        <template slot-scope="scope">
          <el-button size="small" style="background-color: #0096dc" @click="open(scope.row)">处理</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="处理申述" :visible.sync="dialogFormVisible">
      <el-form>
        <el-form-item label="处理内容" prop="connect">
          <el-input type="textarea" v-model="handler"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="background-color: #0096dc" @click="handle()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>


export default {
  data() {
    return {
      dialogFormVisible:false,
      tableData: [],
      handler:'',
      param: {}
    }
  },
  methods: {
    open(row){
      this.dialogFormVisible=true
      this.param = row;
    },

    handle() {

      this.param.handler=this.handler
      console.log(this.param)
      let url = 'http://localhost:8080/allega/handle'
      this.axios.post(url, this.param).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          this.$message({
            showClose: true,
            message: '处理成功',
            type: 'success'
          });
          this.dialogFormVisible=false
          this.loadAllega()
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
          this.loadAllega()
        }
      });
    },
    loadAllega() {
      let url = 'http://localhost:8080/allega/adminLoadAllega'
      this.axios.get(url).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          this.tableData = responseBody.data;
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });

    },
  },
  created() {
    this.loadAllega();
  }
}
</script>

